package cc.uts.edu.au;



import java.util.Random;

import com.google.gson.Gson;

import bean.uts.edu.au.CheckCardRequest;
import bean.uts.edu.au.CheckCardResponse;



//http://www.beachnet.com/~hstiles/cardtype.html
public class MyCCCheck {
	

	public CheckCardResponse checkCard(String jsonData){

		Gson gson = new Gson();
		CheckCardRequest ccrequest=gson.fromJson(jsonData, CheckCardRequest.class);
		String cardNumber=ccrequest.getCardNumber();
		String cardType=ccrequest.getCardType();
		Boolean isvalidBoolean=CardCheck.validateCreditCard(cardNumber,cardType);
		String returnNumberString=CardCheck.processCardNumber(cardNumber);
		int receipt = -1;
		String message="This Credit Card ("+cardType+" "+returnNumberString+") is invalid, Please check again!";
		if (isvalidBoolean){
			Random cuRandom=new Random();
			receipt=cuRandom.nextInt(65535)+1;	
			message="This Credit Card ("+cardType+" "+returnNumberString+") is valid.";
		}
		CheckCardResponse resultCardResponse=new CheckCardResponse(isvalidBoolean, receipt, message);
		return resultCardResponse;
	}
	
	

}
